package com.lzh.springboot.rabbitmqdemo.consumer;

import com.lzh.springboot.rabbitmqdemo.message.Demo01Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Description: 消费者01
 * @Author: LiuZiHao
 * @Date: 2022/5/6 16:06
 */
@Component
@RabbitListener(queues = Demo01Message.QUEUE) //声明了消费的队列是 "QUEUE_DEMO_01"
public class Demo01Consumer {

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * @param message 方法入参为消息的类型
     * @RabbitHandler 申明了处理消息的方法。
     */
    @RabbitHandler
    public void onMessage(Demo01Message message) {
        logger.info("[onMessage][线程编号:{} 消息内容{} ]", Thread.currentThread().getId(), message);
    }

    /**
     * 如果我们想要获得消费消息的更多信息，例如说，RoutingKey、创建时间等等信息
     * 通过方法入参为 org.springframework.amqp.core.Message 类型。
     */
    //    @RabbitHandler(isDefault = true)
    //    public void onMessage(org.springframework.amqp.core.Message message) {
    //        logger.info("[onMessage][线程编号:{} 消息内容：{}]", Thread.currentThread().getId(), message);
    //    }

}
